<?php

namespace app\user\controller;

use app\common\service\UserMoneyService;
use app\user\validate\UserMoneyValidate;
use app\user\model\UserMoney;
use app\common\attributes\RandyValidate;
use app\common\attributes\Menu;
use think\annotation\Inject;
use think\response\Json;
use think\App;

class UserMoneyController  extends UserBaseController
{

    protected UserMoney $model;

    public function __construct(App $app) {
        parent::__construct($app);
        $this->model = new UserMoney();
    }

    #[Inject]
    protected  UserMoneyService $service ;

    #[menu('查看账号资金管理列表')]
    public function index(): Json
    {
         $data = $this->getParams();
         //当前是否为关联查询
         $this->relationSearch = true;
         //设置过滤方法
         $extendQueryHelper = $this->buildparams();
         $list = $this->service->getUserMoneyList($extendQueryHelper, $data);
         foreach ($list as $row) {

         }
         return $this->success($list);
    }
     #[menu('查看账号资金管理列表')]
       public function list(  ){
        $data = $this->getParams();
         //当前是否为关联查询
         $this->relationSearch = true;
         //设置过滤方法
          $extendQueryHelper = $this->buildparams();
          $extendQueryHelper->setIsPage(false);
          $list = $this->service->getUserMoneyList($extendQueryHelper, $data);
           foreach ($list as $row) {

           }
           return $this->success($list);
       }


    #[menu('查看账号资金管理详情')]
    #[RandyValidate(validate: UserMoneyValidate::class, scene: 'read')]
    public function read( $user_money_id ): Json
    {
        $res = $this->service->getUserMoneyItem($user_money_id);
        return $this->returnSuccess($res);
    }

    #[menu('删除账号资金管理')]
    #[RandyValidate(validate: UserMoneyValidate::class, scene: 'del')]
    public function del( $user_money_id ):Json
    {
        $res = $this->service->delUserMoneyItem( $user_money_id );
        return $this->returnSuccess($res);
    }

    #[menu('更新账号资金管理')]
    #[RandyValidate(validate: UserMoneyValidate::class, scene: 'update')]
    public function update( $user_money_id ): \think\response\Json
    {
        $data = $this->getParams();
        $res = $this->service->setUserMoneyItem($user_money_id ,$data);
        return $this->returnSuccess();
    }

    #[menu('新增账号资金管理')]
    #[RandyValidate(validate: UserMoneyValidate::class, scene: 'save')]
    public function save():Json
    {
        $data = $this->getParams();
        $res = $this->service->addUserMoneyItem($data);
        return $this->returnSuccess($res);
    }



}
